# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=libcmis
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.2
pkgrel=3
pkgdesc="C/C++ CMIS client library. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/tdf/libcmis'
msys2_references=(
  'archlinux: libcmis'
)
license=('spdx:MPL-1.1 OR LGPL-2.1-or-later OR GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost-libs"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-libxml2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
source=("https://github.com/tdf/libcmis/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz"
        "001-fix-build-with-boost-1.86.patch::https://github.com/tdf/libcmis/commit/dfcb642a.patch")
sha256sums=('1b5c2d7258ff93eb5f9958ff0e4dfd7332dc75a071bb717dde2217a26602a644'
            '1cc558f7ca46bfcb9e2eb08f62d5c1f2f60581db3986b2ac50d2a1929284ec16')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-fix-build-with-boost-1.86.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --disable-static \
    --disable-werror \
    --without-man \
    LIBS='-lbcrypt'

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

  install -d "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -p -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING* \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
